package model

import (
	"gin-project/utils/errmsg"
	"strconv"
)

type SongListSong struct {
	SongListID int
	SongID       int
}

func (SongListSong) TableName() string {
	return "song_list_song"
}

// 删除歌单内的所有歌曲
func DeleteRelateBySongListID(id string) int {
	convID, _ := strconv.Atoi(id)
	err := db.Where("song_list_id = ?", convID).Delete(&SongListSong{}).Error
	if err != nil {
		return errmsg.SONGLIST_DELETE_RELATE_FAILED
	}
	return errmsg.SUCCESS
}

// 添加歌单和歌曲的关系
func InsertRelate(songListID, songID string) int {
	convSongListID, _ := strconv.Atoi(songListID)
	convSongID, _ := strconv.Atoi(songID)

	var songListSong SongListSong
	songListSong.SongListID = convSongListID
	songListSong.SongID = convSongID

	err := db.Create(&songListSong).Error
	if err != nil {
		return errmsg.SONGLIST_INSERT_RELATE_RELATE
	}
	return errmsg.SUCCESS
}
